<script type="text/javascript">
function TokenAlbumsController(eventId) {
	
	var hiddenTokenAlbumIds = jQuery('#hiddenTokenAlbumIds');
	
	var _eventId = eventId;
	var _albumnIds = [];

	var albumsContainer = jQuery('#albumsContainer')
	
	var GRID_ELEMENT = "gridElement";
	var GRID_ELEMENT_CLASS = '.'+GRID_ELEMENT;
	
	// Bindings	
	this.addAlbumToToken= addAlbumToToken;
	this.deleteAlbumFromToken = deleteAlbumFromToken;
	this.getAlbumsIds = getAlbumsIds;
	this.getEventId = getEventId;
	this.setHiddenFields = setHiddenFields;
	this.getIdFirstAlbum = getIdFirstAlbum;
	
	function addAlbumToToken(anAlbumId) {				
		_albumnIds.push(anAlbumId);	
	}
	
	function deleteAlbumFromToken(anAlbumId) {		
		var idx = _albumnIds.indexOf(anAlbumId);
		if (idx != -1) 
			_albumnIds.splice(idx, 1);		
	}
	
	function getAlbumsIds() {
		return _albumnIds;
	}
	
	function getEventId() {
		return _eventId;
	}
	
	function setHiddenFields() {		
		hiddenTokenAlbumIds.val(_albumnIds);							
	}	

	function getIdFirstAlbum(){
		var firstImage = albumsContainer.find(GRID_ELEMENT_CLASS).first();		  			
		return firstImage.prop('id');
	}
}

</script>